package com.icss.client.controller;

import com.icss.client.model.UserInfoModel;
import com.icss.feign.UserService;
import com.icss.feign.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/* 注册控制器 */
@RestController
public class RegisterController {

    @Autowired
    private UserService userService;

    @RequestMapping(value = "register",method = RequestMethod.POST)
    @ResponseBody
    public String register(UserInfoModel userInfoModel){

        try{
            if(userInfoModel == null){
                return "error.html";
            }
            User user = new User();
            user.setUser_name(userInfoModel.getUserName());
            user.setUser_pwd(userInfoModel.getPassword());

            Boolean result = userService.register(user);
            if(result == null || !result){
                return "error.html";
            }
            return "login.html";
        }catch (Exception ex){
            ex.printStackTrace();
            return "error.html";
        }
    }
}
